import Vue from 'vue'
import VueLazyLoad from 'vue-lazyload'

Vue.use(VueLazyLoad, {
  preLoad: 1.33,
  // error: require('~/static/icons/common/picture-error.png'),
  // loading: require('~/static/icons/common/loading.gif'),
  attempt: 2,
  throttleWait: 500,
  listenEvents: [ 'scroll' ],
  filter: {
    progressive(listener, options) {
      if (listener && listener.src) {
        listener.el.setAttribute('lazy-progressive', 'true');
        // 替换为低像素图片
        let loadingUrl = listener.src.replace(/w_[0-9]+/g, 'w_5');
        loadingUrl = loadingUrl.replace(/h_[0-9]+/g, 'h_5');
        listener.loading = loadingUrl;
      } else {
        console.error('listener.src is undefined');
      }
    }
  }
})
